Added an option to customize the server poll interval in the Advanced Settings
authorPablo Ariño Muñoz <progpabarino@gmail.com>
Tue, 25 Feb 2025 14:43:29 +0000 (15:43 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 26 Feb 2025 11:59:46 +0000 (11:59 +0000)
Signed-off-by: Pablo Ariño Muñoz <progpabarino@gmail.com>
src/gui/generalsettings.cpp
src/gui/generalsettings.h
src/gui/generalsettings.ui
src/libsync/configfile.cpp
src/libsync/configfile.h

index d4a0aeaa4d4a0205ed64a6d72f4dc7096b57d5e6..cf0794a15c17c87190fff698898fde539c63e90b 100644 (file)
@@ -50,6 +50,7 @@
 #include <QMessageBox>
 
 #include <KZip>
+#include <chrono>
 
 namespace {
 struct ZipEntry {
@@ -187,6 +188,8 @@ GeneralSettings::GeneralSettings(QWidget *parent)
 {
     _ui->setupUi(this);
 
+    _ui->labelInterval->setOpenExternalLinks(true);
+
     connect(_ui->serverNotificationsCheckBox, &QAbstractButton::toggled,
         this, &GeneralSettings::slotToggleOptionalServerNotifications);
     _ui->serverNotificationsCheckBox->setToolTip(tr("Server notifications that require attention."));
@@ -240,7 +243,8 @@ GeneralSettings::GeneralSettings(QWidget *parent)
     connect(_ui->stopExistingFolderNowBigSyncCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings);
     connect(_ui->newExternalStorage, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings);
     connect(_ui->moveFilesToTrashCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings);
-
+    connect(_ui->remotePollIntervalSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &GeneralSettings::slotRemotePollIntervalChanged);
+    connect(_ui->remotePollIntervalCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotRemotePollIntervalCheckBoxToggled);
 #ifndef WITH_CRASHREPORTER
     _ui->crashreporterCheckBox->setVisible(false);
 #endif
@@ -321,6 +325,13 @@ void GeneralSettings::loadMiscSettings()
     _ui->stopExistingFolderNowBigSyncCheckBox->setChecked(_ui->existingFolderLimitCheckBox->isChecked() && cfgFile.stopSyncingExistingFoldersOverLimit());
     _ui->newExternalStorage->setChecked(cfgFile.confirmExternalStorage());
     _ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons());
+
+    
+    bool hasCustomInterval = cfgFile.hasRemotePollInterval();
+    _ui->remotePollIntervalCheckBox->setChecked(hasCustomInterval);
+    auto interval = cfgFile.remotePollInterval(); 
+    _ui->remotePollIntervalSpinBox->setValue(static_cast<int>(interval.count() / 1000));  
+    _ui->remotePollIntervalSpinBox->setEnabled(hasCustomInterval);
 }
 
 #if defined(BUILD_UPDATER)
@@ -639,4 +650,31 @@ void GeneralSettings::customizeStyle()
 #endif
 }
 
+void GeneralSettings::slotRemotePollIntervalCheckBoxToggled(bool checked) {
+    _ui->remotePollIntervalSpinBox->setEnabled(checked); // Enable/disable the spin box
+
+    ConfigFile cfgFile;
+
+    if (checked) {
+        slotRemotePollIntervalChanged(_ui->remotePollIntervalSpinBox->value());
+    } else {
+        // Reset to default interval when unchecked
+        cfgFile.resetRemotePollInterval();
+
+        // Update the spinbox with the default value
+        auto interval = cfgFile.remotePollInterval();
+        _ui->remotePollIntervalSpinBox->setValue(static_cast<int>(interval.count() / 1000));
+    }
+}
+
+void GeneralSettings::slotRemotePollIntervalChanged(int seconds) {
+    if (_currentlyLoading) return;
+
+    if (_ui->remotePollIntervalCheckBox->isChecked()) {
+        ConfigFile cfgFile;
+        std::chrono::milliseconds interval(seconds * 1000);
+        cfgFile.setRemotePollInterval(interval);
+    }
+}
+
 } // namespace OCC
index 83067799a9753cb5567eb7a143268b2c52fba2c5..30d02cdf3e8817382237424cb328d56474f2b84a 100644 (file)
@@ -59,6 +59,8 @@ private slots:
     void slotCreateDebugArchive();
     void loadMiscSettings();
     void slotShowLegalNotice();
+    void slotRemotePollIntervalChanged(int seconds);
+    void slotRemotePollIntervalCheckBoxToggled(bool checked);
 #if defined(BUILD_UPDATER)
     void slotUpdateInfo();
     void slotUpdateChannelChanged();
index 65eb6256c8bce7a3aeafa0491bc6b13ff9116f2d..c489485517c5b1777720864b5f95a84836f6f88d 100644 (file)
         </item>
        </layout>
       </item>
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout_remotePollInterval">
+        <item>
+         <widget class="QCheckBox" name="remotePollIntervalCheckBox">
+          <property name="text">
+           <string>Server poll interval</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QSpinBox" name="remotePollIntervalSpinBox">
+          <property name="minimum">
+            <number>30</number>
+          </property>
+          <property name="maximum">
+           <number>3600</number>
+          </property>
+          <property name="singleStep">
+           <number>1</number>
+          </property>         
+         </widget>         
+        </item>
+        <item>
+         <widget class="QLabel" name="labelInterval">
+          <property name="text">
+           <string extracomment="Trailing part of &quot;Server poll interval&quot; ">seconds (if <a href="https://github.com/nextcloud/notify_push">Client Push</a> is unavailable)</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer_remotePollInterval">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout_trash">
         <item>
index 1efd01e5da355610138ca32bc0d81009222658d5..6adb8c2e2bbbc439a8e57eb7e141678011ab73f7 100644 (file)
@@ -1315,4 +1315,25 @@ void ConfigFile::setDiscoveredLegacyConfigPath(const QString &discoveredLegacyCo
     _discoveredLegacyConfigPath = discoveredLegacyConfigPath;
 }
 
+bool ConfigFile::hasRemotePollInterval(const QString &connection) const
+{
+    QString con(connection);
+    if (connection.isEmpty())
+        con = defaultConnection();
+
+    QSettings settings(configFile(), QSettings::IniFormat);
+    settings.beginGroup(con);
+
+    return settings.contains(QLatin1String(remotePollIntervalC));
+}
+
+void ConfigFile::resetRemotePollInterval(const QString &connection) {
+    QString con(connection);
+    if (connection.isEmpty())
+        con = defaultConnection();
+
+    std::chrono::milliseconds defaultInterval(DEFAULT_REMOTE_POLL_INTERVAL);
+    setRemotePollInterval(defaultInterval, con); // Use existing method
+}
+
 }
index f38fba1f11ab047d1d9166a2b8081ed1feab0088..bf6be3548ccb9cdae5d96932a3364b66a185047a 100644 (file)
@@ -153,6 +153,8 @@ public:
     [[nodiscard]] bool useNewBigFolderSizeLimit() const;
     [[nodiscard]] bool confirmExternalStorage() const;
     void setConfirmExternalStorage(bool);
+    [[nodiscard]] bool hasRemotePollInterval(const QString &connection = QString()) const;
+    void resetRemotePollInterval(const QString &connection = QString());
 
     /** If we should move the files deleted on the server in the trash  */
     [[nodiscard]] bool moveToTrash() const;